<template>
  <view class="app">
    <view class="back-btn mix-icon icon-xiangzuo" @click="navBack"></view>
    <view class="page-tip">{{ title }}</view>
    <mescroll-uni
      ref="mescrollRef"
      @init="mescrollInit"
      @down="refreshChange"
      @up="loadChange"
      :down="down"
      :up="up"
      :fixed="true"
      :top="100"
      :bottom="140"
    >
      <view class="wrapper">
        <view class="item-wrap" v-if="detailData != null">
          <view class="wrap-title">货物路线信息</view>
          <view class="item-panel">
            <view class="item row">
              <view class="item1 column">
                <image
                  class="item-img"
                  src="/static/zhuanhg.png"
                  mode="aspectFit"
                ></image>
                <view class="item-line"></view>
                <image
                  class="item-img"
                  src="/static/xie2.png"
                  mode="aspectFit"
                ></image>
              </view>
              <view class="item2 column">
                <view class="item21 item-title row">
                  {{ detailData.loadProvince }} <text class="item-tag"></text>
                  {{ detailData.loadCity }}</view
                >
                <view class="item21 item-desc row">
                  {{ detailData.loadAddress }}</view
                >

                <view class="item22" @click="callClick(detailData.loadPhone)">
                  <image
                    class="item-img"
                    src="/static/show_dianhua.png"
                    mode="aspectFit"
                  ></image>
                </view>
                <view class="item21 item-date row">
                  <image
                    class="date-icon"
                    src="/static/riqi@2x.png"
                    mode="scaleToFill"
                  />
                  {{ detailData.requiredLoadingTime }} 可装
                  {{ detailData.takeGoodsModelLabel }}</view
                >
                <view class="item21 item-line"></view>
                <view class="item21 item-title row">
                  {{ detailData.unloadProvince }}
                  <text class="item-tag"></text>
                  {{ detailData.unloadCity }}</view
                >
                <view class="item21 item-desc row">
                  {{ detailData.unloadAddress }}</view
                >
                <view class="item23" @click="callClick(detailData.unloadPhone)">
                  <image
                    class="item-img"
                    src="/static/show_dianhua.png"
                    mode="aspectFit"
                  ></image>
                </view>
                <view class="item21 item-date row">
                  <image
                    class="date-icon"
                    src="/static/riqi@2x.png"
                    mode="scaleToFill"
                  />
                  {{ detailData.requiredUnloadingTime }} 可卸
                  {{ detailData.distributionGoodsModelLabel }}</view
                >
              </view>
            </view>
          </view>
        </view>
        <view class="item-wrap" v-if="detailData != null">
          <view class="wrap-title">货物信息</view>
          <view class="item-panel">
            <view class="item2 column">
              <view class="item31 item-title row"
                >货源编号
                <text class="desc">{{ detailData.orderNo }}</text></view
              >
            </view>
          </view>
          <view class="item41 item-title row"
            >货物
            <view v-if="detailData.weight && detailData.volume" class="desc"
              >{{ detailData.goodsName }} · {{ detailData.goodsTypeLabel }} ·
              {{ detailData.weight }}吨 · {{ detailData.volume }}方 ·
              {{ detailData.piece }}件</view
            >
            <view v-if="detailData.weight && !detailData.volume" class="desc"
              >{{ detailData.goodsName }} · {{ detailData.goodsTypeLabel }} ·
              {{ detailData.weight }}吨 · {{ detailData.piece }}件</view
            >
            <view v-if="!detailData.weight && detailData.volume" class="desc"
              >{{ detailData.goodsName }} · {{ detailData.goodsTypeLabel }} ·
              {{ detailData.volume }}方 · {{ detailData.piece }}件</view
            >
          </view>
          <view class="item41 item-line"></view>
          <view class="item41 item-title row"
            >车辆 <text class="desc">{{ detailData.vehicleLengthLabel }}</text>
            <text class="silver"></text>
            <text class="desc">{{ detailData.vehicleTypeLabel }}</text>
            <text class="silver"></text>
            <text class="desc">{{ detailData.useVehicleModeLabel }}</text>
          </view>
        </view>
        <view class="item-wrap" v-if="detailData != null">
          <view class="wrap-title">服务要求</view>
          <view class="item-panel">
            <view class="item2 column">
              <view class="item51 item-title row">{{
                detailData.serviceRequire
              }}</view>
            </view>
          </view>
        </view>
        <view class="item-wrap" v-if="detailData != null">
          <view class="wrap-title">货主信息</view>
          <view class="item61">
            <view class="item61-left">
              <image class="logo-icon" src="/static/driver@2x.png"></image>
            </view>
            <view class="item61-right">
              <view class="item61-title">{{ detailData.shipperName }}</view>
              <view class="item61-info">
                <text class="item61-desc"
                  >交易<text class="desc"
                    >{{ detailData.acceptNumber || 0 }}次</text
                  ></text
                >
                <text class="item61-desc"
                  >发货总量<text class="desc"
                    >{{ detailData.dealNumberWeight || 0 }}吨</text
                  ></text
                >
                <text class="item61-desc"
                  >发货总量<text class="desc"
                    >{{ detailData.dealNumberVolume || 0 }}方</text
                  ></text
                >
              </view>
            </view>
          </view>
        </view>
      </view>
    </mescroll-uni>
    <view class="fixed-btn">
      <view class="price" v-if="detailData != null"
        >￥{{ detailData.freight }}<text class="tag">元/趟</text></view
      >
      <mix-button
        v-if="statusNum == 5"
        ref="confirmBtnNG"
        text="拒单"
        :isConfirm="false"
        class="btn-default"
        @onConfirm="showPopup('confirmNgModal')"
      ></mix-button>
      <mix-button
        v-if="statusNum == 5"
        ref="confirmBtnOK"
        text="接单"
        :isConfirm="false"
        style="width: 210rpx; margin-right: 30rpx"
        @onConfirm="showPopup('confirmOKModal')"
      ></mix-button>
    </view>
    <user-confirm
      ref="confirmNgModal"
      title="温馨提示"
      text="确认拒绝当前选择货源吗?"
      @onConfirm="onCancel"
    ></user-confirm>
    <business-modal ref="confirmOKModal" @onConfirm="onSave"></business-modal>
  </view>
</template>

<script>
import userConfirm from "../../components/user-confirm/user-confirm.vue";
import businessModal from "./components/business-modal.vue";
export default {
  components: {
    userConfirm,
    businessModal,
  },
  data() {
    return {
      title: "货源详情",
      id: "",
      detailData: null,
      statusNum: -1,
      mescroll: null,
      up: {
        auto: false, //默认开始不执行上拉
      },
      down: {
        auto: false, //默认开始不执行下拉
      },
    };
  },
  onLoad(e) {
    this.id = e.id;
  },
  methods: {
    navBack() {
      uni.navigateBack();
    },
    mescrollInit(mescroll) {
      this.mescroll = mescroll;
      setTimeout(() => {
        this.getList();
      }, 10);
    },

    refreshChange() {
      console.log("refresh");
      // this.mescroll.removeEmpty(); //移除空布局，主要是第一次无值，第二次有值
      // this.mescroll.showUpScroll(); //显示上拉加载，主要用于标签1加载完END，切换标签2时默认替换END(有切换标签时调用)
      this.detailData = null;
      this.statusNum = -1;
      this.getList();
    },
    loadChange() {
      console.log("load");
      // this.getList();
      // this.mescroll.endSuccess(false); //数量大于默认数量10，否则无法上拉加载,或者修改endSuccess原方法
    },
    async getList() {
      const res = await this.$http.post(`/rest/order/deliver/orderDetails`, {
        keyId: this.id,
      });
      console.log("loadData:", res);
      this.detailData = res.data;
      this.statusNum = res.data.status;
      this.mescroll.endUpScroll(false); //隐藏上拉加载，false为隐藏，其他参考文档(有showUpScroll时调用)
      this.mescroll.endDownScroll(); //隐藏下拉刷新
      this.mescroll.endSuccess(false); //数量大于默认数量10，否则无法上拉加载,或者修改endSuccess原方法
    },
    callClick(phoneNumber) {
      uni.makePhoneCall({
        phoneNumber,
        // phoneNumber: "17521033321",
      });
    },
    onCancel() {
      const keyIdList = [this.detailData.keyId];
      this.$http
        .post(
          `/rest/tran/waybill/refuseBillForCarrier`,
          JSON.stringify(keyIdList)
        )
        .then((res) => {
          if (res.success) {
            this.$util.msg("拒单成功");
            setTimeout(() => {
              this.getList();
            }, 2000);
          }
        });
    },
    onSave() {
      const keyIdList = [this.detailData.keyId];
      this.$http
        .post(
          `/rest/tran/waybill/receiveBillForCarrier`,
          JSON.stringify(keyIdList)
        )
        .then((res) => {
          if (res.success) {
            this.$util.msg("接单成功");
            setTimeout(() => {
              this.getList();
            }, 2000);
          }
        });
    },
  },
};
</script>

<style>
page {
  background: #f7f8f9;
}
</style>
<style scoped lang="scss">
.app {
  padding-top: 90rpx;
  position: relative;
  width: 100vw;
  height: 100vh;
  overflow: hidden;
  background-image: url("../../static/page_bg.png");
  background-repeat: no-repeat;
  background-size: 100% 600rpx;
}
.back-btn {
  position: absolute;
  left: 20rpx;
  top: calc(var(--status-bar-height) + 30rpx);
  z-index: 90;
  padding: 20rpx;
  font-size: 34rpx;
  color: white;
}
.page-tip {
  position: absolute;
  left: 50%;
  top: calc(var(--status-bar-height) + 44rpx);
  z-index: 90;
  margin-left: -80rpx;
  font-size: 34rpx;
  color: white;
  line-height: 34rpx;
}
.wrapper {
  margin-top: calc(var(--status-bar-height) + 20rpx);
}
.item-wrap {
  width: 700rpx;
  margin: 20rpx auto 0;
  padding: 30rpx;
  background: #fff;
  border-radius: 20rpx;
  .wrap-title {
    font-size: 18px;
    font-weight: bold;
    color: #222222;
    line-height: 18px;
    margin: 0rpx auto 30rpx auto;
  }
  .item-panel {
    position: relative;
    background: #f9fafb;
    // height: 320rpx;
    border-radius: 14rpx;
    padding: 20rpx;
    .date-icon {
      width: 30rpx;
      height: 30rpx;
      margin-right: 14rpx;
    }
    .item {
      align-items: start;
      .item1 {
        height: 200rpx;
        justify-content: space-between;
        align-items: center;
        .item-line {
          border-left: 1rpx dashed #979797;
          height: 80rpx;
          width: 1rpx;
        }
        .item-img {
          width: 46rpx;
          height: 46rpx;
        }
      }
      .item2 {
        margin-left: 28rpx;
        justify-content: space-between;
        position: relative;
        width: 100%;
        .item21 {
          height: 46rpx;
          // margin: 5rpx auto;
          align-items: center;
        }
        .item22 {
          position: absolute;
          top: 40rpx;
          right: 10rpx;
          .item-img {
            width: 46rpx;
            height: 46rpx;
          }
        }
        .item23 {
          position: absolute;
          bottom: 40rpx;
          right: 10rpx;
          .item-img {
            width: 46rpx;
            height: 46rpx;
          }
        }
        .item-title {
          font-weight: bold;
        }
        .item-tag {
          display: inline-block;
          margin: auto 16rpx;
          width: 12rpx;
          height: 12rpx;
          border-radius: 12rpx;
          background-color: black;
        }
        .item-line {
          border-bottom: 1rpx solid #d8d8d8;
          width: 100%;
          height: 1rpx;
          margin: 10rpx auto;
        }
        .item-date {
          font-size: 26rpx;
          color: #666666;
        }
      }
    }
    .item31 {
      .desc {
        padding-left: 20rpx;
        font-weight: bold;
      }
    }
  }
  .item41 {
    color: #666;
    margin: 10rpx auto;
    &.item-line {
      width: 100%;
      height: 1rpx;
      border-bottom: 1px solid #d8d8d8;
    }
    .desc {
      color: #222;
      padding-left: 20rpx;
    }
    .silver {
      border-left: 1rpx solid #979797;
      height: 20rpx;
      width: 1rpx;
      margin-left: 20rpx;
    }
  }
  .item51 {
    margin: 5rpx 0;
  }
  .item61 {
    display: flex;
    justify-content: center;
    align-items: center;
    .item61-left {
      width: 160rpx;
      .logo-icon {
        width: 120rpx;
        height: 120rpx;
      }
    }
    .item61-right {
      display: flex;
      flex-direction: column;
      justify-content: space-around;
      margin: 14rpx 0;
      .item61-title {
        margin-left: 10rpx;
        font-weight: bold;
      }
      .item61-info {
        display: flex;
        // justify-content: space-around;
        flex-wrap: wrap;
        margin-left: 10rpx;
        .item61-desc {
          color: #666;
          // font-size: 20rpx;
          margin-right: 30rpx;
          margin-bottom: 10rpx;
          .desc {
            margin-left: 10rpx;
            color: #222;
          }
        }
      }
    }
  }
}

.fixed-btn {
  position: absolute;
  left: 0;
  bottom: 0vh;
  z-index: 1;
  width: 100%;
  height: 140rpx;
  font-size: 24rpx;
  font-weight: bold;
  color: #999;
  background-color: #fff;
  display: flex;
  flex-wrap: wrap;
  // justify-content: space-around;
  align-items: center;
  flex: 1;
  .price {
    color: #f55348;
    margin: auto 25rpx;
    wdith: 200rpx;
    font-size: 44rpx;
    font-weight: bold;
    .tag {
      padding-left: 4rpx;
      font-size: 26rpx;
    }
  }
}
.btn-default {
  width: 210rpx;
  background-color: white;
  border: 1px solid #f75248;
  color: #f5473b;
  &:after {
    background: linear-gradient(151deg, white 0%, rgb(240, 236, 236) 100%);
  }
}
</style>
